home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / lib / php / DB / sybase.php < prev   
Encoding:
PHP Script  |  2001-03-06  |  5.1 KB  |  185 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                   |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Sterling Hughes <sterling@php.net>                          |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: sybase.php,v 1.8 2000/09/13 11:27:59 ssb Exp $
  20. //
  21. // Database independent query interface definition for PHP's Sybase
  22. // extension.
  23. //
  24.  
  25. require_once 'DB/common.php';
  26.  
  27. class DB_sybase extends DB_common {
  28.  
  29.     var $connection;
  30.     var $phptype, $dbsyntax;
  31.     var $prepare_tokens = array();
  32.     var $prepare_types = array();
  33.  
  34.     function DB_sybase() {
  35.         $this->phptype = 'sybase';
  36.         $this->dbsyntax = 'sybase';
  37.         $this->features = array(
  38.             'prepare' => false,
  39.             'pconnect' => true,
  40.             'transactions' => false
  41.         );
  42.     }
  43.  
  44.     function connect ( $dsn, $persistent=false ) {
  45.         if(is_array($dsn)) {
  46.             $dsninfo = &$dsn;
  47.         } else {
  48.             $dsninfo = DB::parseDSN($dsn);
  49.         }
  50.         if (!$dsninfo || !$dsninfo['phptype']) {
  51.             return $this->raiseError(); 
  52.         }
  53.         $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
  54.         $connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect';
  55.         $conn = $dbhost ? $connect_function($dbhost) : false;
  56.         $dsninfo['database'] && @sybase_select_db($dsninfo['database'], $conn);
  57.         $this->connection = $conn;
  58.         return DB_OK;
  59.     }
  60.  
  61.     function disconnect() {
  62.         return @sybase_close($this->connection);
  63.     }
  64.  
  65.     function &query( $stmt ) {
  66.         $this->last_query = $stmt;
  67.         $result = @sybase_query($stmt, $this->connection);
  68.         if (!$result) {
  69.             return $this->raiseError();
  70.         }
  71.         // Determine which queries that should return data, and which
  72.         // should return an error code only.
  73.         if (preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt)) {
  74.             $resultObj = new DB_result($this, $result);
  75.             return $resultObj;
  76.         } else {
  77.             return DB_OK;
  78.         }
  79.     }
  80.  
  81.     function simpleQuery($stmt) {
  82.         $this->last_query = $stmt;
  83.         $result = @sybase_query($stmt, $this->connection);
  84.         if (!$result) {
  85.             return $this->raiseError();
  86.         }
  87.         // Determine which queries that should return data, and which
  88.         // should return an error code only.
  89.         return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt) ? $result : DB_OK;
  90.     }
  91.  
  92.     function &fetchRow($result, $fetchmode=DB_FETCHMODE_DEFAULT) {
  93.         if ($fetchmode == DB_FETCHMODE_DEFAULT) {
  94.             $fetchmode = $this->fetchmode;
  95.         }
  96.         $row = ($fetchmode & DB_FETCHMODE_ASSOC) ? @sybase_fetch_array($result) : @sybase_fetch_row($result);
  97.         if (!$row) {
  98.             return $this->raiseError();
  99.         }
  100.         return $row;
  101.     }
  102.  
  103.     function fetchInto($result, &$ar, $fetchmode=DB_FETCHMODE_DEFAULT) {
  104.         if ($fetchmode == DB_FETCHMODE_DEFAULT) {
  105.             $fetchmode = $this->fetchmode;
  106.         }
  107.         $ar = ($fetchmode & DB_FETCHMODE_ASSOC) ? @sybase_fetch_array($result) : @sybase_fetch_row($result);
  108.         if (!$ar) {
  109.             return $this->raiseError();
  110.         }
  111.         return DB_OK;
  112.     }
  113.  
  114.     function freeResult($result) {
  115.         if (is_resource($result)) {
  116.             return @sybase_free_result($result);
  117.         }
  118.         if (!isset($this->prepare_tokens[$result])) {
  119.             return false;
  120.         }
  121.         unset($this->prepare_tokens[$result]);
  122.         unset($this->prepare_types[$result]);
  123.         return true; 
  124.     }
  125.  
  126.     function numCols($result) {
  127.         $cols = @sybase_num_fields($result);
  128.         if (!$cols) {
  129.             return $this->raiseError();
  130.         }
  131.         return $cols;
  132.     }
  133.  
  134.     function prepare($query) {
  135.         $tokens = split('[\&\?]', $query);
  136.         $token = 0;
  137.         $types = array();
  138.         for ($i = 0; $i < strlen($query); $i++) {
  139.             switch ($query[$i]) {
  140.                 case '?':
  141.                     $types[$token++] = DB_PARAM_SCALAR;
  142.                     break;
  143.                 case '&':
  144.                     $types[$token++] = DB_PARAM_OPAQUE;
  145.                     break;
  146.             }
  147.         }
  148.         $this->prepare_tokens[] = &$tokens;
  149.         end($this->prepare_tokens);
  150.         $k = key($this->prepare_tokens);
  151.         $this->prepare_types[$k] = $types;
  152.         return $k;
  153.     }
  154.  
  155.     function execute($stmt, $data = false) {
  156.         $realquery = $this->execute_emulate_query($stmt, $data);
  157.         $this->last_query = $realquery;
  158.         $result = @sybase_query($realquery, $this->connection);
  159.         if (!$result) {
  160.             return $this->raiseError();
  161.         }
  162.         return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $realquery) ? $result : DB_OK;
  163.     }
  164.  
  165.     function autoCommit($onoff=false) {
  166.         return $this->raiseError(DB_ERROR_NOT_CAPABLE);
  167.     }
  168.  
  169.     function commit() {
  170.         return $this->raiseError(DB_ERROR_NOT_CAPABLE);
  171.     }
  172.  
  173.     function rollback() {
  174.         return $this->raiseError(DB_ERROR_NOT_CAPABLE);
  175.     }
  176. }
  177.  
  178. /*
  179.  * Local variables:
  180.  * tab-width: 4
  181.  * c-basic-offset: 4
  182.  * End:
  183.  */
  184. ?>
  185.